<template>

	<view>
		<view v-if="islog" class="flex j-c a-c" style="height: 180rpx;background-color: #fff;">
			<image style="width: 50rpx;height: 50rpx;" src="@/static/icon/lo.gif" mode=""></image>
		</view>


		<view v-if="!islog" class="pr2 pl2 pb2" v-for="(item,index) in list" :key="index">
			<view class="p20 b_y flex   " style="background-color: #fff;">
				<view class="" @click="on_view(index)">
					<image class="b_y" style="width: 160rpx;height: 160rpx;" :src="item.shop_img|getImg"></image>
				</view>
				<view @click="on_view(index)" style="margin-left: 10rpx;width:450rpx ;">
					<text class="f30 w800 ml1 yihang" style="width: 350rpx;">{{item.shop_name}}</text>
					<view class="pt1  yihang" style="margin-left: 15rpx;">
						<text class="  f26" style="color: #999999;">{{item.shop_tag}}</text>
					</view>
					<view class="pt1 yihang" style="margin-left: 15rpx;">
						<text class="f26" style="color: #999999;">投稿时间:{{item.creation_time|getTime}}</text>
					</view>

					<view v-if="type==2&&item.status==0" class="pt1 yihang" style="margin-left: 15rpx;">
						<text class="f26 cred">拒绝原因:{{item.refuse_text}}</text>
					</view>
				</view>


			</view>


			<view class="flex j-f p2" v-if="type==2">
				<text class="banmi_button_2" style="background-color: #4169E1;">
					{{item.status==0?'已拒绝': item.status==1?'审核中': item.status==2?'已通过': '取消收藏'	}}
				</text>
				<text @click="on_edit(index)" class="banmi_button_2 ml1">编辑</text>
			</view>
			<view @click="on_del(index)" class="flex j-f p2" v-if="type==1">
				<text class="banmi_button_del ml2">删除</text>
			</view>
		</view>
		<view v-if="!islog&&list.length>10" class="flex j-c a-c" style="height: 180rpx;">
			<text class="f24 c_pl1">{{log}}</text>
		</view>
		<view v-if="!islog&&list.length==0" class="flex j-c a-c" style="height: 180rpx;background-color: #fff;">
			<text class="f24 c_pl1">暂无数据</text>
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			options: {
				type: Object,
				default: function(e) {
					return {}
				}
			},
			list: {
				type: Array,
				default: function() {
					return [] //数据
				},
			},
			islog: {
				type: Boolean, //是否显示边框
				default: true
			},
			log: {
				type: String,
				default: ''
			},

			index: {
				type: Number,
				default: 0
			},
			time: {
				type: Number,
				default: 0
			},
			type: {
				type: Number,
				default: 0
			},
		},

		filters: {
			timeStamp1: function(timestamp) {

				function zeroize(num) {
					return (String(num).length == 1 ? '0' : '') + num;
				}

				var curTimestamp = parseInt(new Date().getTime() / 1000); //当前时间戳
				var timestampDiff = curTimestamp - timestamp; // 参数时间戳与当前时间戳相差秒数

				var curDate = new Date(curTimestamp * 1000); // 当前时间日期对象
				var tmDate = new Date(timestamp * 1000); // 参数时间戳转换成的日期对象

				var Y = tmDate.getFullYear(),
					m = tmDate.getMonth() + 1,
					d = tmDate.getDate();
				var H = tmDate.getHours(),
					i = tmDate.getMinutes(),
					s = tmDate.getSeconds();

				if (timestampDiff < 60) { // 一分钟以内
					return "刚刚";
				} else if (timestampDiff < 3600) { // 一小时前之内
					return Math.floor(timestampDiff / 60) + "分钟前";
				} else if (curDate.getFullYear() == Y && curDate.getMonth() + 1 == m && curDate.getDate() == d) {
					return '今天' + zeroize(H) + ':' + zeroize(i);
				} else {
					var newDate = new Date((curTimestamp - 86400) * 1000); // 参数中的时间戳加一天转换成的日期对象
					if (newDate.getFullYear() == Y && newDate.getMonth() + 1 == m && newDate.getDate() == d) {
						return '昨天' + zeroize(H) + ':' + zeroize(i);
					} else if (curDate.getFullYear() == Y) {
						return zeroize(m) + '月' + zeroize(d) + '日 ' + zeroize(H) + ':' + zeroize(i);
					} else {
						return Y + '年' + zeroize(m) + '月' + zeroize(d) + '日 ' + zeroize(H) + ':' + zeroize(i);
					}
				}
			}

		},
		data() {
			return {
				lat: '',
				lng: '',


			}
		},
		mounted() {
			var pages = getCurrentPages()
			let currentRoute = pages[pages.length - 1].route;
			this.api_path = currentRoute.match(/pages\/(\S*)\//)[1];
			this.lat = uni.getStorageSync('lat')
			this.lng = uni.getStorageSync('lng')

		},


		methods: {
			on_edit(index) {
				var id = this.list[index]['id'];
				console.log("id: " + JSON.stringify(id));
				uni.navigateTo({
					url: '/pages/' + this.api_path + '/shop_add?id=' + id
				})


			},
			on_del(index) {
				var that = this;
				uni.showModal({
					title: '提示',
					content: '确认删除？',
					success: function(res) {
						if (res.confirm) {
							that.$emit('on_del', index)
						}
					}
				});
			},
			on_view(index) {
				var id = this.list[index]['id']
				uni.navigateTo({
					url: '/pages/' + this.api_path + '/shop_view?id=' + id
				})
			},
			on_tel(phone) {

				uni.makePhoneCall({
					phoneNumber: phone,
					success: function() {

					}

				})

			}

		}
	}
</script>

<style>
	
	.banmi_button_1{
		background-color: #09BB07;
		display: flex;
		justify-content: center;
		align-items: center;
		width: 120rpx;
		height: 50rpx;
		border-radius: 5px;
		color: #fff;
		font-size: 28rpx;
	}
	.banmi_button_2{
		background-color: #09BB07;
		display: flex;
		justify-content: center;
		align-items: center;
		width: 120rpx;
		height: 50rpx;
		color: #fff;
		font-size: 28rpx;
		border-radius: 25px;
		color: #fff;
	}
</style>